package C;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class C30 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<int[]> list = new ArrayList<>();
        for (int i=0;i<n;i++) {
            list.add(new int[]{sc.nextInt(),sc.nextInt()});
        }
        getResult(list);
    }
    public static void getResult(ArrayList<int[]> list) {
        Collections.sort(list,(a, b)-> a[0]-b[0]);
        int[] pre = new int[]{list.get(0)[0],list.get(0)[1]};
        int[] cur = new int[2];
        if (list.size()==1) {
            System.out.println(pre[0]+" "+pre[1]);
            return ;
        }
        for (int i=1;i< list.size();i++) {
            cur[0] = list.get(i)[0];
            cur[1] = list.get(i)[1];
            if (pre[1]>=cur[0]) {
                pre[1] = Math.max(pre[1],cur[1]);
            } else {
                System.out.println(pre[0]+" "+pre[1]);
                pre[0] = cur[0];
                pre[1] = cur[1];
            }
        }
        System.out.println(pre[0]+" "+pre[1]);
    }
}
